/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: '#main',
    data: {
       	friendprovince : {},
    },
    created: function () {
    	if(location.search != ""){
    		this.modinit();
    	}else{
    		$("#keep").css("display","");
    	}
    },
    methods: {
    	//修改进入初始化
    	modinit:function(){
    		$("#mod").css("display","");
    		_data = {};
    		url = location.search.split("=");
    		_data.id = url[1]
    		App.ajax({
    			type:"POST",
    			url:App.getApiUrl("modfriend"),
    			data:_data,
    			success:function(data){
    				$("#friend_no").val(data.OPT_NO);
    				$("#friend_name").val(data.OPT_NAME);
    				$("#mod_optid").val(data.OPT_ID);
    				$("#mod_id").val(data.id);
    				if(data.companyType == 1){
    					$("#leixing .am-fl").text("保险");
    					$("#lei").val(data.companyType);
    				} 
    				if(data.OPT_STATUS == 1){
    					$("#stats .am-fl").text("有效");
    					$("#sta").val(data.OPT_STATUS);
    				}else{
    					$("#stats .am-fl").text("无效");
    					$("#sta").val(data.OPT_STATUS);
    				}
    				$("#beginDay").val(data.applicationDate);
    				$("#phone").val(data.phone);
    				$("#email").val(data.email);
				}
    		})
    	},
    	//新增方法
    	submit:function(){
    		var _data = {};
    		var reg = /^1[3|4|5|7|8][0-9]{9}$/;
    		var eam = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    		if($("#friend_no").val() == ""){
    			parent.showAlert("请输入登录账号");
    			return;
    		}else{
    			_data.optNo = $("#friend_no").val();
    		};
    		if($("#friend_name").val() == ""){
    			parent.showAlert("请输入公司名称");
    			return;
    		}else{
    			_data.optName = $("#friend_name").val();
    		};
    		if($("#friend_pro").find("option:selected").val() == ""){
    			parent.showAlert("请选择用户类型");
    			return;
    		}else{
    			_data.companyType = $("#friend_pro").find("option:selected").val();
    		};
    		_data.optStatus = $("#friend_stats").find("option:selected").val();
    		if($("#beginDay").val() == ""){
    			parent.showAlert("请输入是我申请日期");
    			return;
    		}else{
    			_data.applicationDate = $("#beginDay").val();
    		};
    		if($("#phone").val() == ""){
    			parent.showAlert("请输入联系方式");
    			return;
    		}else if(reg.test($("#phone").val()) == false){
    				parent.showAlert("请输入正确电话号码");
    				return;
    		}else{
    			_data.phone = $("#phone").val();
    		};
    		if($("#email").val() == ""){
    			parent.showAlert("请输入邮箱");
    			return;
    		}else if(eam.test($("#email").val()) == false){
    			parent.showAlert("请输入正确邮箱");
				return;
    		}else{
    			_data.email = $("#email").val();
    		};
    		if($("#password").val() == ""){
    			parent.showAlert("请输入密码");
    			return;
    		}else{
    			_data.optPassword = $("#password").val();
    		};
    		if($("#password_d").val() == ""){
    			parent.showAlert("请再次输入确认密码");
    			return;
    		}else{
    			_data.optPasswordT = $("#password_d").val();
    		};
    		App.ajax({
    			type:"POST",
    			url:App.getApiUrl("addfriend"),
    			data:_data,
    			success:function(data){
    				window.location.href = App.getBaseUrl() + "sys/task/friendcheck.html";
				}
    		})
    	},
    	//修改方法
    	modsubmit:function(){
    		var _data = {};
    		var reg = /^1[3|4|5|7|8][0-9]{9}$/;
    		var eam = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    		if($("#friend_no").val() == ""){
    			parent.showAlert("请输入登录账号");
    			return;
    		}else{
    			_data.optNo = $("#friend_no").val();
    		};
    		if($("#friend_name").val() == ""){
    			parent.showAlert("请输入公司名称");
    			return;
    		}else{
    			_data.optName = $("#friend_name").val();
    		};
    		if($("#friend_pro").find("option:selected").val() == ""&&$("#lei").val() == ""){
    			parent.showAlert("请选择用户类型");
    			return;
    		}else if($("#friend_pro").find("option:selected").val() != ""){
    			_data.companyType = $("#friend_pro").find("option:selected").val();
    		}else{
    			_data.companyType = $("#lei").val();
    		};
    		if($("#friend_stats").find("option:selected").val() == "" && $("#sta").val() != ""){
    			_data.optStatus = $("#sta").val();
    		}else if($("#friend_stats").find("option:selected").val() != ""){
    			_data.optStatus = $("#friend_stats").find("option:selected").val();
    		}
    		if($("#beginDay").val() == ""){
    			parent.showAlert("请输入申请日期");
    			return;
    		}else{
    			_data.applicationDate = $("#beginDay").val();
    		};
    		if($("#phone").val() == ""){
    			parent.showAlert("请输入联系方式");
    			return;
    		}else if(reg.test($("#phone").val()) == false){
    				parent.showAlert("请输入正确电话号码");
    				return;
    		}else{
    			_data.phone = $("#phone").val();
    		};
    		if($("#email").val() == ""){
    			parent.showAlert("请输入邮箱");
    			return;
    		}else if(eam.test($("#email").val()) == false){
    			parent.showAlert("请输入正确邮箱");
				return;
    		}else{
    			_data.email = $("#email").val();
    		};
    		if($("#password").val() == ""){
    			parent.showAlert("请输入密码");
    			return;
    		}else{
    			_data.optPassword = $("#password").val();
    		};
    		if($("#password_d").val() == ""){
    			parent.showAlert("请再次输入确认密码");
    			return;
    		}else{
    			_data.optPasswordT = $("#password_d").val();
    		};
    		_data.optId = $("#mod_optid").val();
    		_data.id = $("#mod_id").val();
    		App.ajax({
    			type:"POST",
    			url:App.getApiUrl("updatefriend"),
    			data:_data,
    			success:function(data){
    				 window.location.href = App.getBaseUrl() + "sys/task/friendcheck.html";
				}
    		})
    	},
        friend_return:function(){
            window.location.href = App.getBaseUrl() + "sys/task/friendcheck.html";
        }
    },
});

